package com.xl.juc.collection.unsafe;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * java.util.ConcurrentModificationException
 * 解决方案
 * new ConcurrentHashMap<>();
 * @author Charley
 * @create 2020-12-27
 */
public class MapTest {
    public static void main(String[] args) {
        //默认等价为：new HashMap<>(16,0.75f);
        Map<String, String> hashMap = new ConcurrentHashMap<>();
        //加载因子  初始化容量
        for (int i = 0; i <100 ; i++) {
            new Thread(()->{
                hashMap.put(Thread.currentThread().getName(),UUID.randomUUID().toString().substring(0,5));
                System.out.println(hashMap);
            },String.valueOf(i)).start();
        }
    }
}
